#include "MenuSystem.h"
#include "IrControl.h"
#include <fcntl.h>
#include "Menu/Tool/frame.h"



int			TestColorFocus = -1;
TFrame			TestColorFrame;
extern unsigned char rece_handle;	
extern unsigned char dtpresent_flag;
extern pthread_cond_t dt_cond;


int TestColorGetTouchID( TPosCoor pos )
{
	if ( ((pos.x>0) && (pos.x <480)) && ((pos.y>0) && (pos.y <720)) )
			return 1;
	/*	if( ut_PtInRect( pos, MenuVideoTouchRect[i] ) )
				{				
				return i;
				}
		*/
	return -1;
}


void TestColorDraw( BOOL bDrawAll )
{

	char FileName[20];
	
	g_FillRect( TestColorFrame.pCanvas, 0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, RGB_BLACK );
	sprintf( FileName, "%d/%d.jpg", TEST_DISP_FOLDER, IMG_TEST_COLOR_ITEM);
	DrawJpeg(TestColorFrame.pCanvas, 0, 0, FileName );		
	dtpresent_flag++;		
	pthread_cond_signal(&dt_cond);
	//dt_Present();
}



BOOL TestColorBtnEnter(int idx)
{

	TestMainInit(1);
	dtpresent_flag++;		
	pthread_cond_signal(&dt_cond);
	return TRUE;
}


void TestColorInit()
{
	ir_SetCurrentID( IR_TEST_COLOR);
	frm_Create( &TestColorFrame, FRM_NO_TITLE|FRM_NO_TASK, "" );
	TestColorDraw( TRUE );
	printf ("in TestColorInit ~~\n");
	
}


void TestColorInput(UInt32 key)
{
		
		
	if( key == IRC_TOUCH_DOWN || key == IRC_TOUCH_UP )
	{
		int focus;
		TPosCoor pos;
		dt_ClipTouchGetXY( &pos.x, &pos.y );
		if( key == IRC_TOUCH_DOWN )
		{
			if( LastKey ==IRC_TOUCH_UP )
			{
				if( ( TestColorFocus = TestColorGetTouchID( pos )) != -1 )
				{
					printf ("in TestColor,pressed!\n");
				}
			}
		}
		else
		{
			if( ( focus = TestColorGetTouchID( pos ) ) == TestColorFocus )
				TestColorBtnEnter( TestColorFocus );
			
			TestColorFocus = -1;
		}
		LastKey = key;//hangsheng add 071126
	}
	
}




